package org.bud.boot.configuration;

import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.boot.autoconfigure.MybatisProperties;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;

/**
 * @author shaun
 * @date 2024/7/25
 * @instruction
 */
@Configuration
public class MybatisConfiguration implements InitializingBean {

    @Autowired
    private MybatisProperties mybatisProperties;

    @Value("${env:dev}")
    private String env;

    @Override
    public void afterPropertiesSet() throws Exception {
        if("dev".equals(env)){
            if (this.mybatisProperties.getConfiguration() == null) {
                this.mybatisProperties.setConfiguration(new org.apache.ibatis.session.Configuration());
            }
            this.mybatisProperties.getConfiguration().setLogImpl(StdOutImpl.class);
        }
    }
}
